package com.hk.controller;

import com.hk.Enume.OperationType;
import com.hk.annotation.AotoFile;
import com.hk.constant.LogConstaant;
import com.hk.core.Result;
import com.hk.core.roleResult.PageRoleResult;
import com.hk.domain.Activity;
import com.hk.dto.ActivityDto;
import com.hk.dto.AddActivityDto;
import com.hk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//活动相关
@Slf4j

@RestController
@RequestMapping("/clues/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;
//    查询所有活动
@GetMapping("list")
    public PageRoleResult list(@ModelAttribute ActivityDto activityDto){


    return activityService.list(activityDto);
}
//添加活动
    @AotoFile(value = OperationType.POST,title = LogConstaant.ACTIVITY_LOG)
@PostMapping()
    public Result addActivit(@RequestBody AddActivityDto activityDto){
    activityService.addActivit(activityDto);
    return Result.success();
}
//根据id查询活动
@GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){

    return Result.success(activityService.selectById(id));
}
//根据id修改活动
    @AotoFile(value = OperationType.PUT,title = LogConstaant.ACTIVITY_LOG)
@PutMapping()
    public Result modifyActivit(@RequestBody AddActivityDto activity){
    activityService.modifyActivit(activity);
    return Result.success();
}
//根据id删除活动
    @AotoFile(value = OperationType.DELETE,title = LogConstaant.ACTIVITY_LOG)
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
    activityService.deleteById(id);

    return Result.success();
    }
//    根据类型查询活动
    @GetMapping("/listselect/{type}")
    public Result listByType(@PathVariable Integer type){

    return Result.success(activityService.listByType(type));

    }
}
